function timeAgo(pastTimestamp) {
    const now = new Date();
    const past = new Date(pastTimestamp);
    const msPerMinute = 60 * 1000;
    const msPerHour = msPerMinute * 60;
    const msPerDay = msPerHour * 24;
    const msPerMonth = msPerDay * 30; // 注意：这不是每个月都准确，但对于简单的计算足够了

    const elapsed = now - past;

    if (elapsed < msPerMinute) {
        return Math.round(elapsed / 1000) + '秒前';
    } else if (elapsed < msPerHour) {
        return Math.round(elapsed / msPerMinute) + '分钟前';
    } else if (elapsed < msPerDay) {
        return Math.round(elapsed / msPerHour) + '小时前';
    } else if (elapsed < msPerMonth) {
        return Math.round(elapsed / msPerDay) + '天前';
    } else {
        return past.getFullYear() + '年' + (past.getMonth() + 1) + '月' + past.getDate() + '日';
    }
}

export {
    timeAgo
};
